import * as React from 'react';
import {observer} from 'mobx-react';
import {Table, Row, Col, Button, message} from 'antd';
import {PositionBaseFormModal} from '../form/Form';
import {editStore, listStore, searchStore} from '../PositionStore';

@observer
export class EditFormModal extends React.Component<any, any> {
    onOk(me){
        return function(){
            if(editStore.isValid()){
                editStore.changeConfirmLoading(true);
                
                editStore.editPosition(editStore.getValues())
                    .then((data)=>{
                        if(data.success){
                            message.success(data.message,3);
                            editStore.hide();
                            listStore.load(searchStore.getValues());
                        }else{
                            message.error(data.message,3);
                        }

                        editStore.changeConfirmLoading(false);
                    })
            }else{
                return false;
            }
        }
    }

    render() {
        return <PositionBaseFormModal store={editStore} title="编辑" onOk={this.onOk(this)}/>
    }
}
